package com.quartet.modules.customer.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.quartet.modules.customer.dao.TCustomerInfoDao;
import com.quartet.modules.customer.entity.TCustomerInfo;
import com.quartet.modules.customer.service.TCustomerInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 客户信息表(TCustomerInfo)表服务实现类
 *
 * @author makejava
 * @since 2021-05-04 16:25:16
 */
@Service("tCustomerInfoService")
public class TCustomerInfoServiceImpl extends ServiceImpl<TCustomerInfoDao, TCustomerInfo> implements TCustomerInfoService {

    @Autowired
    private TCustomerInfoDao tCustomerInfoDao;

//    /**
//     * 查询客户树
//     *
//     * @return
//     */
//    @Override
//    public List<TCustomerInfoResponseDto> selectCustomerTree() {
//        QueryWrapper<TCustomerInfo> wrapper = new QueryWrapper();
////        wrapper.orderByDesc("id");
//        List<TCustomerInfo> tCustomerInfoList = baseMapper.selectList(wrapper);
//        List<TCustomerInfo> result = build(tCustomerInfoList);
//        List<TCustomerInfoResponseDto> tCustomerInfoResponseDtoList = BeanTool.copyObjListProperties(result, TCustomerInfoResponseDto.class);
//        return tCustomerInfoResponseDtoList;
//    }

    /**
     *  给客户的关联终端个数加个数
     * @param customerCode
     * @param count
     */
    @Override
    public void updateCustomerAssignedTerminalsNum(String customerCode,int count) {
        tCustomerInfoDao.updateCustomerAssignedTerminalsNum(customerCode,count);
    }

//    /**
//     * 使用递归方法获取客户树
//     *
//     * @param tCustomerInfoList
//     * @return
//     */
//    private static List<TCustomerInfo> build(List<TCustomerInfo> tCustomerInfoList) {
//        List<TCustomerInfo> treeNodes = new ArrayList();
//        for (TCustomerInfo tCustomerInfo : tCustomerInfoList) {
//            if (StringUtils.isBlank(tCustomerInfo.getParentCustomerCode())) {
////                tCustomerInfo.setLevel(1);
//                treeNodes.add(findChildren(tCustomerInfo, tCustomerInfoList));
//            }
//        }
//        return treeNodes;
//    }
//
//    /**
//     * 递归查找子节点
//     * @param tCustomerInfo
//     * @param tCustomerInfoList
//     * @return
//     */
//    private static TCustomerInfo findChildren(TCustomerInfo tCustomerInfo,List<TCustomerInfo> tCustomerInfoList) {
//        tCustomerInfo.setChildren(new ArrayList<>());
//
//        for (TCustomerInfo treeNode : tCustomerInfoList) {
//            if(tCustomerInfo.getCustomerCode().equals(treeNode.getParentCustomerCode())) {
////                int level = treeNode.getLevel() + 1;
////                it.setLevel(level);
//                if (tCustomerInfo.getChildren() == null) {
//                    tCustomerInfo.setChildren(new ArrayList<>());
//                }
//                tCustomerInfo.getChildren().add(findChildren(treeNode,tCustomerInfoList));
//            }
//        }
//        return tCustomerInfo;
//    }
}
